package com.gg.ai.service;

import com.gg.ai.mapper.ChatHistoryMapper;
import com.gg.ai.pojo.JsonVariable;
import com.gg.ai.pojo.TextDTO;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RestController;

public class HandleHistory implements Runnable {


    @Override
    public void run() {
        System.out.println(JsonVariable.historyList);
        JsonVariable.historyList = JsonVariable.historyList == null? "[]" :JsonVariable.historyList;
        Gson gson = new Gson();
        TextDTO[] textDTOS = gson.fromJson(JsonVariable.historyList, TextDTO[].class);
        // 打印数组内容
        for (TextDTO textDTO : textDTOS) {
//            System.out.println("Role: " + textDTO.getRole() + ", Content: " + textDTO.getContent());
            JsonVariable.textArray.add(createJsonObject(textDTO.getRole(), textDTO.getContent()));
        }
        JsonVariable.textArray.add(createJsonObject("user",JsonVariable.question));
//        JsonVariable.textArray.add(createJsonObject("system", "你现在扮演李白，你豪情万丈，狂放不羁；接下来请用李白的口吻和用户对话。"));
//        JsonVariable.textArray.add(createJsonObject("user", "你是谁"));
//        JsonVariable.textArray.add(createJsonObject("assistant", "....."));
//        JsonVariable.textArray.add(createJsonObject("user", "你会做什么"));
//        JsonVariable.textArray.add(createJsonObject("user", "你会做什么"));

        JsonVariable.messageObject.add("text", JsonVariable.textArray);
//        JsonVariable.messageObject.add("text", chatHistoryService.queryList(JsonVariable.userId).getHistoryList());

        JsonVariable.payloadObject.add("message", JsonVariable.messageObject);

        JsonVariable.historyList = String.valueOf(JsonVariable.messageObject.get("text"));
    }

    private JsonObject createJsonObject(String role, String content) {
        JsonObject obj = new JsonObject();
        obj.addProperty("role", role);
        obj.addProperty("content", content);
        return obj;
    }


}
